// TypeScript file
class DaZhaoBar extends egret.Sprite
{
    private rect: egret.Rectangle;
    public w: number = 0;
    private b: number = 0;
    public rx: number = 1;
    public boo: boolean = false;
    private bar: egret.Bitmap;
    constructor()
    {
        super();
    }

    public initView(): void
    {
        let bg: egret.Bitmap = ResourceUtils.createBitmapByName("dazhaoBarBg_png"); 
        this.addChild(bg);
        this.bar = ResourceUtils.createBitmapByName("dazhao_png");
        this.addChild(this.bar);

        bg.x = -2;
        bg.y = 2;
        this.bar.y = bg.y + 2;
       
        this.w = this.bar.width;
        this.rect = new egret.Rectangle();
        this.b = this.bar.x - this.bar.width;
        this.rect.x = this.b;
        this.rect.y = 0;
        this.rect.width = this.bar.width;
        this.rect.height = this.bar.height;
        this.bar.mask = this.rect;
        egret.Ticker.getInstance().register(this.onFrameHandler, this);

    }

    private onFrameHandler(): void
    {
        if (!this.boo) return;
        this.rect.x = this.rx;
    }

    public setValue(): void
    {
        if (this.boo) return;
        if (GameData.profectNum > GameData.dazhaoTime)
        {
            GameData.profectNum = GameData.dazhaoTime;
        }

        this.rect.x = -(this.w - this.w * (GameData.profectNum / GameData.dazhaoTime));
        this.bar.mask = this.rect;
    }
}